cc.Class({
    extends: cc.Component,

    properties: {

        bgmVolume: 1.0,
        sfxVolume: 1.0,

        bgmAudioID: -1,
    },

    onload: function() {

    },

    init: function() {
        cc.game.on(cc.game.EVENT_HIDE, function() {
            console.log("cc.audioEngine.pauseAll");
            cc.audioEngine.pauseAll();
        });
        cc.game.on(cc.game.EVENT_SHOW, function() {
            console.log("cc.audioEngine.resumeAll");
            cc.audioEngine.resumeAll();
        });

    },

    getUrl: function(url) {
        return cc.url.raw("resources/sound/" + url + ".mp3");
    },
    getUrlBg: function(url) {
        return cc.url.raw("resources/bg/" + url + ".mp3");
    }, 
    getUrlOther: function(url) {
        return cc.url.raw("resources/othersound/" + url + ".mp3");
    },

    getBgmName() {
        return this.bgm;
    },
    playBGM(url) {
        this.bgm = url;
        cc.audioEngine.stopAll();
        var audioUrl = this.getUrlBg(url);
        this.bgmAudioID = cc.audioEngine.play(audioUrl, true, this.bgmVolume);
    },

    playSFX(url) {
        var audioUrl = this.getUrl(url);
        var audioId = cc.audioEngine.play(audioUrl, false, this.sfxVolume);
    },
    
    playBtnClick(url) {
        var audioUrl = this.getUrlOther(url);
        var audioId = cc.audioEngine.play(audioUrl, false, this.sfxVolume);
    },

    pauseBg() {
        cc.audioEngine.pause(this.bgmAudioID);
    },
    resumeBg() {
        cc.audioEngine.resume(this.bgmAudioID);
    },

    //暂停所有音乐
    pauseAll: function() {
        cc.audioEngine.pauseAll();
    },

    //恢复所有音乐
    resumeAll: function() {
        cc.audioEngine.resumeAll();
    }
});